﻿using System;
using System.Collections.Generic;
using CrystalDecisions.CrystalReports.Engine;
using ATSDAL;
using ATSModel;

public partial class Calibration_CaliTestDetails_ViewTTestItem : System.Web.UI.Page
{
    private ReportDocument doc = new ReportDocument();

    private void Page_Unload(object sender, EventArgs e)
    {
        doc.Dispose();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        this.Page.Unload += new EventHandler(Page_Unload);
    }

    public IList<TCalRecordItemInfo> GetData()
    {
        IList<TCalRecordItemInfo> testItems = new List<TCalRecordItemInfo>();
        TCalibrationItem testItem = new TCalibrationItem();
        string str1 = (string)Session["InstrumentID"];
        DateTime dt1 = (DateTime)Session["RecordTime"];

        testItems = testItem.GetTestItems(str1, dt1);
        return testItems;
    }

    protected void CrystalReportViewer1_Init(object sender, EventArgs e)
    {
        ForCrystalReport();
    }

    protected void ForCrystalReport()
    {
        doc.Load(Server.MapPath("cailbrationItem.rpt"));

        TextObject txtProductSN = (TextObject)doc.ReportDefinition.ReportObjects["Text1"];
        txtProductSN.Text = "互调仪序列号：" + (string)Session["InstrumentID"];

        TextObject txtRecordTime = (TextObject)doc.ReportDefinition.ReportObjects["Text2"];
        txtRecordTime.Text = "校对时间：" + (string)Session["RecordTime"].ToString();
        
        TextObject txtIsPass = (TextObject)doc.ReportDefinition.ReportObjects["Text3"];
        txtIsPass.Text = "是否通过：" + (string)Session["IsPass"];

        TextObject txtUserID = (TextObject)doc.ReportDefinition.ReportObjects["Text4"];
        txtUserID.Text = "校对人员1：" + (string)Session["UserID"];

        TextObject txtUserID2 = (TextObject)doc.ReportDefinition.ReportObjects["Text5"];
        txtUserID2.Text = "校对人员2：" + (string)Session["UserID2"];



        IList<TCalRecordItemInfo> list = GetData();
        doc.SetDataSource(list);
        this.CrystalReportViewer1.ReportSource = doc;
    }

}
